package main

import (
	"encoding/json"
	"io"
	"net/http"
	"video_server/api/defs"
)

// 返回错误信息
func sendErrorResponse(w http.ResponseWriter, errResp defs.ErrorResponse) {
	//[01] 错误状态码
	w.WriteHeader(errResp.HttpSC)
	//[02] 将错误信息格式化为json字符串
	resStr, _ := json.Marshal(&errResp.Error)
	//[03] 写入响应体中
	io.WriteString(w, string(resStr))
}

//返回正常信息
func sendNormalResponse(w http.ResponseWriter, resp string, statusCode int) { //业务信息不同，返回的数据也不同，所以状态码和错误信息分开
	w.WriteHeader(statusCode)
	io.WriteString(w, resp)
}
